package com.zzyl.member.controller;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.member.dto.FamilyDto;
import com.zzyl.member.dto.QueryDevicePropertyStatusDto;
import com.zzyl.member.service.FamilyService;
import com.zzyl.member.vo.FamilyMyVo;
import com.zzyl.member.vo.FamilyPage;
import com.zzyl.nursing.dto.DeviceDto;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * TODO
 *
 * @Author mr.wu
 * @Date 2025/10/29 19:25
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属相关接口")
public class FamilyController extends BaseController {

    @Autowired
    private FamilyService familyService;

    /**
     * 添加老人信息
     * @param dto
     * @return
     */
    @PostMapping("/add")
    public AjaxResult  addFamily(@RequestBody FamilyDto dto) {
        familyService.add(dto);
        return AjaxResult.success();
    }

    /**
     * 查询家人列表
     * @return
     */
    @GetMapping("/my")
    public AjaxResult myFamily(){
        List<FamilyMyVo> list = familyService.selectMyFamily();
        return AjaxResult.success(list);
    }

    /**
     * 分页查询家人列表详细
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/list-by-page")
    public AjaxResult listByPage( Integer pageNum,  Integer pageSize) {
        List<FamilyPage> list = familyService.listByPage(pageNum,pageSize);
        return AjaxResult.success(list);
    }

    /**
     * 查询设备数据
     * @param dto
     * @return
     */
    @PostMapping("QueryDevicePropertyStatus")
    public AjaxResult queryDevicePropertyStatus(@RequestBody DeviceDto dto){
        Map<String,Object> listMap= familyService.queryDevicePropertyStatus(dto);
         return AjaxResult.success(listMap);
    }


    /**
     * 按天查询设备数据信息
     * @param dto
     * @return
     */
    @GetMapping("/queryDeviceDataListByDay")
    public AjaxResult queryDeviceDataListByDay(QueryDevicePropertyStatusDto dto){
        List<Map<String,Object>> list = familyService.queryDeviceDataListByDay(dto);
        return AjaxResult.success(list);
    }

    /**
     * 按周查询设备数据信息
     * @param dto
     * @return
     */
    @GetMapping("/queryDeviceDataListByWeek")
    public AjaxResult queryDeviceDataListByWeek(QueryDevicePropertyStatusDto dto){
        List<Map<String,Object>> list =familyService.queryDeviceDataListByWeek(dto);
        return AjaxResult.success(list);
    }

    /**
     * 解绑老人
     * @param id
     * @return
     */
    @DeleteMapping("/deleteById")
    public AjaxResult deleteById(@RequestParam Integer id) {
        familyService.deleteById(id);
        return AjaxResult.success();
    }
}